<?php
function load_restore_absen(){ 
	$query = "SELECT   karyawan_id , nik ,  njam  FROM temp_tmn_kjk";
	$result = my_query($query);
$i=0;
	while($ey = my_fetch_array($result)){
		$karyawan = loaddata_karyawan($ey['karyawan_id']);
		$nominal =  2 * $ey['njam']  * $karyawan['gapok_km'] /    173  ;
		$querys = "UPDATE temp_tmn_kjk SET nominal ='{$nominal}' WHERE karyawan_id = {$ey['karyawan_id']} ";
		my_query($querys );
$i++;
	}
return $i;
}


function set_database_email_nik(){
	$end=get_batas_tmt() ;
	$query = " SELECT a.karyawan_id,a.nik FROM karyawan a
			INNER JOIN kekaryawanan b ON b.karyawan_id = a.karyawan_id 
			WHERE b.tmb  <= '{$end}' 
			AND a.karyawan_id NOT IN (select karyawan_id FROM karyawan_disable)
			AND a.karyawan_id NOT IN (select karyawan_id FROM pemberhentian  WHERE tmt <= '{$end}') 	
		";	
	$result = my_query($query);
	$i=0;
	while($row = my_fetch_array($result) ){
		$i++;
		$email_km = $row['nik'].'@hr-kmh.com';
		$update = "UPDATE kekaryawanan
		SET email_km = '{$email_km}'
		WHERE karyawan_id = {$row['karyawan_id']}";
		my_query($update);
	}
	return $i;
}


function parse_update_overtime(){
	$query = " SELECT * FROM temp_tmn_overtime ";
	$result = my_query($query);
	$i=0;
	while($row = my_fetch_array($result)){
		update_overtime( $row['tmn_lembur_id'] , $row['karyawan_id'] , $row['hourpay'] );
		$i++;
	}
	return $i;
}

function update_overtime($data_id , $karyawan_id , $hourpay){
	$karyawan = loaddata_karyawan($karyawan_id);
	
	$payment = $karyawan['gapok_km'] *  $hourpay /173;
	$query_update = "UPDATE temp_tmn_overtime
		SET nominal = '{$payment}'
		WHERE tmn_lembur_id = {$data_id} "; 
	return my_query( $query_update );
}